//
//  MessageShowView.m
//  GuoBang
//
//  Created by 梧桐树 on 16/4/29.
//  Copyright © 2016年 梧桐树. All rights reserved.
//

#import "MessageShowView.h"

@implementation MessageShowView

-(instancetype)initWithFrame:(CGRect)frame{
    
    
    self = [super initWithFrame:frame];
    if (self) {
      
        
    }
    return self;
}
-(void)loadMessage{
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(7, 7, 40, 20)];
    label.text = self.introStr;
    label.font=[UIFont systemFontOfSize:15];
    //自动折行设置
    // label.lineBreakMode = NSLineBreakByWordWrapping;
    label.numberOfLines = 0;
    
    //自适应高度
    CGRect txtFrame = label.frame;
    //宽度
    txtFrame.size.width =[label.text boundingRectWithSize:
                          CGSizeMake(WIDTH*3/4, CGFLOAT_MAX)
                                                  options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                               attributes:[NSDictionary dictionaryWithObjectsAndKeys:label.font,NSFontAttributeName, nil] context:nil].size.width;
    txtFrame.size.height =[label.text boundingRectWithSize:
                           CGSizeMake(txtFrame.size.width, CGFLOAT_MAX)
                                                   options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                                attributes:[NSDictionary dictionaryWithObjectsAndKeys:label.font,NSFontAttributeName, nil] context:nil].size.height;
    
    [self addSubview:label];
    
    
    
    
    label.frame = CGRectMake(7,7,txtFrame.size.width,txtFrame.size.height);
    self.layer.cornerRadius=5;
    self.frame=CGRectMake(self.frame.origin.x, self.frame.origin.y, txtFrame.size.width+14, label.frame.size.height+14);
}
-(void)loadPhoto{
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
   
    if (![fileManager fileExistsAtPath:self.introStr]) {
        NSLog(@"空");
    }else{
        NSLog(@"非空");
    }
    //新闻图片
    image=[[UIImageView alloc]initWithFrame:CGRectMake(7, 7, WIDTH*3/5-10, 10)];
    image.userInteractionEnabled = YES;
    UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
    [image addGestureRecognizer:singleTap1];
    NSLog(@"%@--photo",self.introStr);
    UIImage *photo = [[UIImage alloc] initWithContentsOfFile:self.introStr];
    [image setImage:photo];
    NSLog(@"%@--imnage",image.image);
    image.frame=CGRectMake(7, 7, WIDTH*3/5-10, image.image.size.height/image.image.size.width*(WIDTH*3/5-10));
    [self addSubview:image];
    self.layer.cornerRadius=5;
    self.frame=CGRectMake(self.frame.origin.x, self.frame.origin.y, image.frame.size.width+14, image.frame.size.height+14);
}
-(void)tap{
    [self.delegate photoMore:image.image];

}
@end
